<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">











<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>jxls - JDBC ResultSet Export</title>
    <style type="text/css" media="all">
      @import url("../css/maven-base.css");
      @import url("../css/maven-theme.css");
      @import url("../css/site.css");
    </style>
    <link rel="stylesheet" href="../css/print.css" type="text/css" media="print" />
          <meta name="author" content="Leonid Vysochyn" />
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
      </head>
  <body class="composite">
    <div id="banner">
                  <a href="http://jxls.sourceforge.net" id="bannerLeft">
    
            jXLS
    
            </a>
                          <span id="bannerRight">
    
                                    <img src="http://sourceforge.net/sflogo.php?group_id=141729&type=1" alt="" />
    
            </span>
            <div class="clear">
        <hr/>
      </div>
    </div>
    <div id="breadcrumbs">
          
  

  
    
  
  
    
            <div class="xleft">
        Last Published: 13 Nov 2014
                      </div>
            <div class="xright">            <a href="http://sourceforge.net/projects/jxls" class="externalLink">jXLS on Sourceforge</a>
            
  

  
    
  
  
    
  </div>
      <div class="clear">
        <hr/>
      </div>
    </div>
    <div id="leftColumn">
      <div id="navcolumn">
           
  

  
    
  
  
    
                   <h5>Overview</h5>
            <ul>
              
    <li class="none">
                    <a href="../index.html">Home</a>
          </li>
              
    <li class="none">
                    <a href="http://sourceforge.net/project/showfiles.php?group_id=141729" class="externalLink">Downloads</a>
          </li>
              
    <li class="none">
                    <a href="../reference/installation.html">Installation</a>
          </li>
          </ul>
              <h5>Reference</h5>
            <ul>
              
    <li class="none">
                    <a href="../reference/simplebeans.html">Simple Beans</a>
          </li>
              
    <li class="none">
                    <a href="../reference/tags.html">Using Tags</a>
          </li>
              
    <li class="none">
                    <a href="../reference/sqlreporting.html">SQL Reporting</a>
          </li>
              
    <li class="none">
                    <a href="../reference/collections.html">Collections</a>
          </li>
              
    <li class="none">
                    <a href="../reference/advancedcollections.html">Advanced Collections</a>
          </li>
              
    <li class="none">
                    <a href="../reference/dynamicsheets.html">Dynamic Sheets</a>
          </li>
              
    <li class="none">
                    <a href="../reference/expressions.html">Using Expressions</a>
          </li>
              
    <li class="none">
                    <a href="../reference/formulas.html">Formulas Notation</a>
          </li>
              
    <li class="none">
                    <a href="../reference/poiaccess.html">POI Objects Access</a>
          </li>
              
    <li class="none">
                    <a href="../reference/columnhiding.html">Column Hiding</a>
          </li>
              
    <li class="none">
                    <a href="../reference/sheetoperations.html">Spreadsheet Operations</a>
          </li>
              
    <li class="none">
                    <a href="../reference/customprocessor.html">Custom Processor</a>
          </li>
              
    <li class="none">
              <strong>JDBC ResultSet</strong>
        </li>
              
    <li class="none">
                    <a href="../reference/reader.html">XLS Reader</a>
          </li>
          </ul>
              <h5>Samples</h5>
            <ul>
              
    <li class="none">
                    <a href="../samples/tagsample.html">Tags Sample</a>
          </li>
              
    <li class="none">
                    <a href="../samples/chartsample.html">Charts</a>
          </li>
              
    <li class="none">
                    <a href="../samples/reportsample.html">Reporting Sample</a>
          </li>
              
    <li class="none">
                    <a href="../samples/collectionsample.html">Collections</a>
          </li>
              
    <li class="none">
                    <a href="../samples/adjacentlists.html">Adjacent Lists</a>
          </li>
              
    <li class="none">
                    <a href="../samples/dynamicstylesample.html">Dynamic Style</a>
          </li>
              
    <li class="none">
                    <a href="../samples/resultsetsample.html">JDBC ResultSet</a>
          </li>
              
    <li class="none">
                    <a href="../samples/dynamiccolumnssample.html">Dynamic Columns</a>
          </li>
          </ul>
              <h5>Project Documentation</h5>
            <ul>
              
                
              
      
            
      
            
      
              
        <li class="collapsed">
                    <a href="../project-info.html">Project Information</a>
                </li>
          </ul>
                                           <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
            <img alt="Built by Maven" src="../images/logos/maven-feather.png"></img>
          </a>
                       
  

  
    
  
  
    
        </div>
    </div>
    <div id="bodyColumn">
      <div id="contentBox">
        <div class="section"><h2><a name="Overview"></a>Overview</h2>
<p>Though <a class="externalLink" href="http://jxls.sourceforge.net">jXLS</a> was not designed to export JDBC query results it can be easily done
                using dynabean classes from Jakarta <a class="externalLink" href="http://commons.apache.org/beanutils/">Commons BeanUtils</a>. There are two ways to export
            <code>ResultSet</code> object with <code>XLSTransformer</code>. First one uses <code>org.apache.commons.beanutils.RowSetDynaClass</code>.
            Second one is based on <code>net.sf.jxls.report.ResultSetCollection</code> class.
            </p>
</div>
<div class="section"><h2><a name="RowSet_based_export"></a>RowSet based export</h2>
<p> When you construct an instance of <code>org.apache.commons.beanutils.RowSetDynaClass</code>,
                    the underlying data are copied into a set of in-memory DynaBeans that represent the result.
                    So you can immediately close the <code>ResultSet</code>, normally before you even process the actual data that was returned.
                    But the disadvantage is that you must pay the performance and memory costs of copying the result data.</p>
<p>To use this approach first you have to construct new <code>RowSetDynaClass</code> instance passing your ResultSet to it.</p>
<div class="source"><pre>
                        ResultSet resultSet = ...
                        RowSetDynaClass rowSet = new RowSetDynaClass(resultSet, false);
                    </pre>
</div>
<p>Second constructor parameter indicates that property names should not be lowercased in resulted collection of dynamic beans.
                    After you have initialized instance of <code>RowSetDynaClass</code> you can invoke its <code>getRows()</code> method
                    to get collection of DynaBeans which can be exported in common way.</p>
<div class="source"><pre>
                        Map beans = new HashMap();
                        beans.put( &quot;employee&quot;, rowSet.getRows() );
                        XLSTransformer transformer = new XLSTransformer();
                        transformer.transformXLS( templateFileName, beans, destFileName);
                		</pre>
</div>
<p>See <a href="../samples/resultsetsample.html">ResultSet sample</a> for more details.</p>
</div>
<div class="section"><h2><a name="ResultSet"></a>ResultSet</h2>
<p> If you don't want to load all <code>ResultSet</code> data in memory and agree to keep database connection open
                    while processing all data you may use <code>net.sf.jxls.report.ResultSetCollection</code> class.
                    This class takes <code>ResultSet</code> object as a parameter and implements <code>Collection</code> interface
                    to operate with underlying data. In its turn <code>ResultSetCollection</code> uses <code>org.apache.commons.beanutils.ResultSetDynaClass</code>
                    to return retrieved data as dynamic objects.</p>
<p>Usage of <code>net.sf.jxls.report.ResultSetCollection</code> class is as easy as</p>
<div class="source"><pre>
                    ResultSetCollection rsc = new ResultSetCollection(resultSet, false);
                    beans.put( &quot;employee&quot;, rsc );
                </pre>
</div>
<p>The second constructor argument indicates that property names should not be lowercased before processing. </p>
<p>See <a href="../samples/resultsetsample.html">ResultSet sample</a> for more details</p>
</div>

      </div>
    </div>
    <div class="clear">
      <hr/>
    </div>
    <div id="footer">
      <div class="xright">&#169;  
          2005-2014
    
          jXLS Team
          
  

  
    
  
  
    
  </div>
      <div class="clear">
        <hr/>
      </div>
    </div>
  </body>
</html>
